package com.train.user.controller;

import com.train.common.core.controller.BaseController;
import com.train.common.core.domain.AjaxResult;
import com.train.user.domain.UserPlanProgress;
import com.train.user.dto.PlanProgressDTO;
import com.train.user.service.UserPlanProgressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 计划进度 控制器
 *
 * @author train
 */
@Slf4j
@RestController
@RequestMapping("/user/planprogress")
public class UserPlanProgressController extends BaseController {
    @Autowired
    private UserPlanProgressService userPlanProgressService;

    public AjaxResult getPlanProgress() {
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult updatePlanProgress(@RequestBody PlanProgressDTO planProgress) {
        log.info("用户更新计划进度");
        planProgress.setUserId(getUserId());
        UserPlanProgress userPlanProgress = userPlanProgressService.updatePlanProgress(planProgress);
        return AjaxResult.success("更新计划进度成功", userPlanProgress);
    }


    @PostMapping("/reset/{planId}")
    public AjaxResult resetPlanProgress(@PathVariable Long planId){
        // 调用服务重置指定计划的进度
        boolean result = userPlanProgressService.resetPlanProgress(planId, getUserId());
        if (result) {
            return AjaxResult.success("重置计划进度成功");
        } else {
            return AjaxResult.error("重置计划进度失败");
        }
    }

}